<!--layuimini-main layuimini-panel-->
<div class=" layuimini-mainx layuimini-panel" style="overflow:hidden;margin:0px;padding:0px" >

  <div class="layui-row layui-col-space5 ">
  <div class="layui-col-xs4" style="min-width:400px">

			<form class="layui-form" action="">
			<div class="layui-tab layui-tab-card" >
			  <ul class="layui-tab-title">
				<li class="layui-this" >基本参数</li>
				<li>响应处理</li>
			  </ul>
			  <div class="layui-tab-content"  style="height:500px;border-bottom:1px solid #e0e0e0">

			  <div class="layui-tab-item layui-show " style="overflow:visible;">
			 
				<div class="layui-form " >

					<div class="layui-form-item" >
						<div class="layui-inline" >
							<!--<label class="layui-form-label" style="white-space:nowrap">应答超时(毫秒)</label>
							<div class="layui-input-block" style="width: 80px;">
								<input type="number" min="100" max=""  step="100"  name="resptimeout"  value="1000" autocomplete="off"  class="layui-input">
							</div> -->
							<label class="layui-form-label"  >通讯端口</label>
							<div class="layui-input-block" style="width: 200px;">
								<select name="port_name" id="port_name" lay-filter="port_name" lay-verType="tips" lay-verify="port_name">
								</select>
							</div>
						</div>
					</div>

					  <div class="layui-form-item" >
						<div class="layui-inline">
							<label class="layui-form-label required" alt="范围为:（0-255）">设备地址</label>
							<div class="layui-input-block" style="width: 60px;">
								<input type="number" name="slaveid" oninputx="if(value>255)value=255;if(value<0)value=0" lay-verType="tips" id="slaveid" lay-verify="slaveid" onchange="javascript:makeReq(this)" min="0" max="255" value="1" class="layui-input">
								<input type="hidden" name="port_type" id="port_type">
								<input type="hidden" name="type" id="type">
								<input type="hidden" name="data_type" id="data_type">

							</div>
						</div> 
					</div>
					

					<div class="layui-form-item" >
						<div class="layui-inline">
							<label class="layui-form-label required">对象名称</label>
							<div class="layui-input-block" style="width: 155px;">
								<input type="text" name="cmd_name" id="cmd_name" lay-verify="required|cmd_name" maxlength="100" lay-verType="tips" placeholder="请输入对象名称" value="新对象" class="layui-input">
							</div>
						</div>
					</div>
					
					<div class="layui-form-item" >
						<div class="layui-inline" style="width:98%">
							<label class="layui-form-label required">功能码</label>
							<div class="layui-input-block" >
									<select name="funcCode" id="funcCode" style="z-Index:55555" lay-filter="funcCode" lay-verType="tips" lay-verify="funcCode"></select>
							</div>
						</div>
				  </div>

				  <div class="layui-form-item">
						<div class="layui-inline ">
								<label class="layui-form-label required">地址模式</label>
								<div class="layui-input-block">
									<input type="radio" name="addrmode" autocomplete="off" value="Dec" title="十进制" checked="" lay-filter="ChoiceRadio">
									<input type="radio" name="addrmode" value="Hex" title="十六进制" lay-filter="ChoiceRadio">
								</div>
						</div>
					</div>


					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label required">寄存器地址</label>
							<div class="layui-input-block"  style="width: 60px;">
								<input type="text" lay-verType="tips"  name="address" id="address" max="65535" min="0" lay-verify="address" onchange="javascript:makeReq(this)"  autocomplete="off"  value="0" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label" >数量</label>
							<div class="layui-input-block" style="width: 60px;">
								<input type="number" lay-verType="tips" name="quantity" id="quantity" lay-verify="quantity" value="1" max="2000" min="1" onchange="javascript:makeReq(this)" autocomplete="off"  class="layui-input">
							</div>
						</div>
						
					</div>

					<div class="layui-form-item layui-form-text">
						<label class="layui-form-label">备注</label>
						<div class="layui-input-block">
							<textarea name="desc" class="layui-textarea"  autocomplete="off"></textarea>
						</div>
					</div>
					<div class="layui-form-item layui-form-text">

					<fieldset class="layui-elem-field layui-field-title"  style="margin-bottom:0px;margin-top:0px">
						<legend style="font-size:14px">请求指令</legend>
						   <div class="layui-form-item">
								<label class="layui-form-label">RTU</label>
								<div class="layui-input-block">
									<input disabled class="layui-input" id="RTU_CMD" style="color:#000;font-size:12px"></input>
								</div>
							</div>
							 <div class="layui-form-item">
								<label class="layui-form-label">ASCII</label>
								<div class="layui-input-block">
									<input disabled class="layui-input"  id="ASCII_CMD" style="color:#000;font-size:12px"></input>
								</div>
							</div>
					</fieldset>
					</div>

					<div class="layui-form-item layui-form-text" style="margin-bottom:10px">
						<fieldset class="layui-elem-field layui-field-title" style="margin-bottom:5px;margin-top:0px">
							<legend style="font-size:14px">返回数据</legend>
								<div class="layui-form-item"> 
									<div class="" style="text-align:right;">
										<input type="radio" name="selbyteorder" value="B" title="B" lay-filter="selbyteorder"   autocomplete="off"  checked="" >
										<input type="radio" name="selbyteorder" value="BS" title="BS" lay-filter="selbyteorder"   autocomplete="off"   >
										<input type="radio" name="selbyteorder" value="L" title="L" lay-filter="selbyteorder"  >
										<input type="radio" name="selbyteorder" value="LS" title="LS" lay-filter="selbyteorder"  >
									</div>
								</div>
							    <div class="layui-form-item"> 
									<div class="layui-input-block">
										<input type="text" disabled class="layui-input" id="pollresponse" style="color:#000;font-size:12px"></input>
<!--										<div id="binaryresponse"></div>-->
									</div>
								</div>
						</fieldset>
					</div>



					<div class="layui-form-item">
						<label class="layui-form-label"></label>
						<div class="layui-input-block"> 
							<button class="layui-btn layui-btn-normal layui-btn-sm layui-btn-warm" lay-submit="" lay-filter="testBtn" id="testBtn">测试</button>
							<button type="button" class="layui-btn layui-btn-normal layui-btn-sm layui-btn-warm" id="looptestBtn">循环测试</button>
							<button class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="saveBtn" >保存</button>
							<button type="button" class="layui-btn layui-btn-sm layui-btn-danger" id="closeBtn">关闭</button>
						</div>
					</div> 
				</div><!--end layui-form-->

			  </div><!--end layui-tab-item-->

			  <div class="layui-tab-item  " style="overflow:visible;">xx
			  </div>


			</div><!--layui-tab-content-->

			</div><!--layui-tab--> 
	</div><!--layuimini-left -->
	<div class="layui-col-xs8"  >
		<table class="layui-table" id="dataTable" lay-filter="dataTable" style="margin-top: -10px;"></table>
	</div>
</div>

</div>
<form>

<script type="text/html" id="datatoolbar">
		  <div class="layui-btn-container">
		    <button class="layui-btn layui-btn-sm " lay-event="smartCheck">智能识别</button>
			<div class="layui-btn-group" style="margin-top:-5px;padding:0px">
					<input type="checkbox" title="16位" checked lay-event="CheckDataType">
					<input type="checkbox" title="32位" checked lay-event="CheckDataType">
					<input type="checkbox" title="64位"  lay-event="CheckDataType">
			 </div> 
		  </div> 
</script>

<script>
	var addrMode ="Dec" ;
	
	 function $$(id){
		return document.getElementById(id);
	 }
	
	function getfunction(){
		var obj= $$("funcCode");
		var index=obj.selectedIndex; //序号，取当前选中选项的序号      
		var val = obj.options[index].value;  
		if (val=="") {return "XX"};
		return val;
	}
	
	function makeReq(obj){
		//alert ($$('#slaveid').val());
		var t_addr =parseInt(  $$("slaveid").value );
		var t_address =parseInt(  $$("address").value );
		if (addrMode=="Hex"){
			 t_address =parseInt(  $$("address").value,16 );
		}
		var t_quantity =parseInt(  $$("quantity").value );
		var t_function =   getfunction()   ;
		var asciicmd="";
		var cmd = num2Hex(t_addr );
		cmd += " ";
		cmd += t_function;
		cmd += " ";
		cmd += num2HexBytes(t_address,2," ");
		cmd += "";
		cmd += num2HexBytes(t_quantity,2," ");
		crc = CRC.ToModbusCRC16(cmd,true," ");
		cmd += crc

		cmd = cmd.toUpperCase();
		asciicmd = RTUCMDToASCII(cmd," ");
		/*
		if (t_quantity%2==0){
			$('input:radio[name="selbyteorder"]').removeAttr("disabled").removeProp("disabled");
			$("input:radio[name='selbyteorder']").next().removeClass('layui-radio-disbaled layui-disabled');
		}else{
			//$('input:radio[name="selbyteorder"][value="B"]').prop("checked","true");
			$('input:radio[name="selbyteorder"]').attr("disabled", true).prop("disabled", true);
			$("input:radio[name='selbyteorder']").next().addClass('layui-radio-disbaled layui-disabled');
			layui.form.render()
		}*/
		$("#RTU_CMD").val(cmd); 

		$("#ASCII_CMD").val(asciicmd); 

	}
	var cmddata=[];      
	var responsecmds =[];
    layui.use(['form', 'table'], function () {
        var form = layui.form,
            layer = layui.layer,
            table2 = layui.table,
            $ = layui.$; 

			$("#cmd_name").focus();
			try{
			$('input:radio[name="selbyteorder"][value="'+getCookie("selbyteorder")+'"]').prop("checked","true");
			}catch(ex){}
		//function setTable(data = []) {
				table2.render({
					elem: '#dataTable'
					//,width:950,
					,height: 564
					,width :800
					//,data: data
					,data:cmddata
					,toolbar: '#datatoolbar'  
					,fixed: 'left'
					//,cellMinWidth: 'auto'
					,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
					  title: '提示'
					  ,layEvent: 'LAYTABLE_TIPS'
					  ,icon: 'layui-icon-tips'
					}]
					,cols: [[
						{field: 'idx',sort:false,align:"center",width:45,templet:function(dat){ if(dat["state"]==0 ) { return "---"}else{ return dat["idx"]}  }},
						{field: 'name', title: '别名'},//,edit: 'text'
						{field: 'hex', title: '字节' ,align:"left"},//parseInt( dat["v"],16)
						{field: 'bool', title: '值' ,align:"left",event: 'setbool'},//parseInt( dat["v"],16)
						{field: 'int16',title:'INT16',align:"left",event: 'setint16'},//, title:'int16',width:80  ,templet:function(dat){ try{return toInt16( dat["v"]) ;} catch(error) {} }
						{field: 'uint16',title:'UINT16',align:"left",event: 'setuint16'},//, title:'uint16',width:80  ,templet:function(dat){ try{return toUint16( dat["v"]) ;} catch(error) {} }
						{field: 'int32', title:'INT32',align:"right",event: 'setint32'},//templet:function(dat){ try{return toInt16( dat["v"]) ;} catch(error) {} } },
						{field: 'uint32', title:'UINT32',align:"right",event: 'setuint32'},
						{field: 'float32', title:'FLOAT32',align:"right",event: 'setfloat32'},
						{field: 'int64', title:'INT64',align:"right" ,hide:true,event: 'setint64'},
						{field: 'uint64', title:'UINT64',align:"right" ,hide:true,event: 'setuint64'},
						{field: 'double64', title:'DOUBLE64',align:"right" ,hide:true,event: 'setdouble64'}
					]],
					page: false,
					even: false,
					skin: 'line,row',
					limit: 65535,
					id:"dataTable",
					done:function(res,curr,count){ // 隐藏列
						if($("#data_type").val()=="bit"){
							$("[data-field='hex']").css("display","none");
							$("[data-field='bool']").css("display","");
							$("[data-field='int16']").css("display","none");
							$("[data-field='uint16']").css("display","none");
							$("[data-field='int32']").css("display","none");
							$("[data-field='uint32']").css("display","none");
							$("[data-field='int64']").css("display","none");
							$("[data-field='uint64']").css("display","none");
							$("[data-field='float32']").css("display","none");
							$("[data-field='double64']").css("display","none");
					   }else{ 
							$("[data-field='hex']").css("display","");
							$("[data-field='bool']").css("display","none");
							$("[data-field='int16']").css("display","");
							$("[data-field='uint16']").css("display","");
							$("[data-field='int32']").css("display",needShow(2));
							$("[data-field='uint32']").css("display",needShow(2));
							$("[data-field='int64']").css("display",needShow(4));
							$("[data-field='uint64']").css("display",needShow(4));
							$("[data-field='float32']").css("display",needShow(2));
							$("[data-field='double64']").css("display",needShow(4));
					   } 
					   //$(".layui-table-body, .layui-table-box, .layui-table-cell").css('overflow', 'visible');
					}
				});
		//}

		table2.on('tool(dataTable)', function(obj){
			var data = obj.data;
			//console.log(obj.data);
			if( obj.event.startsWith("set") ){
			  var vv = obj.event.replace("set","");
			  if (data[vv] =="---")return ;
			  layer.prompt({
				formType: 2
				,title: '修改序号为 ['+ data.idx +'] 的别名'
				,value: ""
			  }, function(value, index){
				layer.close(index);
				//这里一般是发送修改的Ajax请求
				responsecmds.push({"id":data["idx"],"name":value,"numtype":vv});
				//同步更新表格和缓存对应的值
				obj.update({
				  sign: vv,
				  name: value+"["+vv+"]"
				});
				
			  });
			}
		});

		function needShow(num){
			if (parseInt($("#quantity").val())>= num ) {
				return "";
			}else{
				return "none";
			}
		}
		//setTable(cmddata);	
		form.render();

		function cleanDatTable(){
			cmddata=[];
		}
 		function displaydatTable(dat,datatype){
			//hex2binarystr(dat);
			var quantity=$("#quantity").val();
			cleanDatTable();
			var dat = hexToBytes(dat);
			var len = dat.length;
			var cselbyteorder= $('input[name="selbyteorder"]:checked').val() ;
			if (datatype=="bit"){
				
				for (var i=0;i<len;i++)
				{
					//console.log(num2binarystr(dat[i],true));
					var bstr = num2binarystr(dat[i],true).trim();
					for (var x=0;x<bstr.length;x++){
						if ((x+i*8)>=quantity) {
							cmddata.push({"sign":"","name":"---","idx":i*8+x,"bool":"---" ,"state":0 });
						}else{
							cmddata.push({"sign":"","name":"位"+(i*8+x),"idx":i*8+x,"bool": bstr.substring(x,x+1) ,"state":1 });
						} 
					}
				}
			}else if (datatype=="word"){
				var idx=0;
				var int32= 0;
				var uint32= 0;
				var int16= 0;
				var uint16= 0;
				var int64= 0;
				var uint64= 0;
				var float32= 0.0;
				var double64 = 0.0;
				var h16  = "";
				for (var i=0;i<len;i+=2)
				{
					h16 = (num2Hex(dat[i])+""+num2Hex(dat[i+1])).toUpperCase();
					var tnum=new XNumber();
					tnum.setByteOrder(cselbyteorder);//|L
					/*if (i%4==0 && len>=2 ) tnum.setHexString(num2Hex(dat[i])+""+num2Hex(dat[i+1]));
					if (i%4==0 && len>=4 ) tnum.setHexString(num2Hex(dat[i])+""+num2Hex(dat[i+1])+""+num2Hex(dat[i+2])+""+num2Hex(dat[i+3]) );
					if (i%8==0 && len>=8 ) tnum.setHexString(num2Hex(dat[i])+""+num2Hex(dat[i+1])+""+num2Hex(dat[i+2])+""+num2Hex(dat[i+3]) +""+num2Hex(dat[i+4]) +""+num2Hex(dat[i+5]) +""+num2Hex(dat[i+6]) +""+num2Hex(dat[i+7]));
					*/
					if (i%2==0 && len>=2 ) tnum.setBytes(dat.slice(i,i+2));
					if (i%4==0 && len>=4 ) tnum.setBytes(dat.slice(i,i+4));
					if (i%8==0 && len>=8 ) tnum.setBytes(dat.slice(i,i+8));

					int16 = tnum.toInt16();
					uint16 = tnum.toUint16();
					int32 = tnum.toInt32();
					uint32 = tnum.toUint32();
					int64 = tnum.toInt64();
					uint64 = tnum.toUint64();
					float32 = tnum.toFloat32();
					double64 = tnum.toFloat64();
					cmddata.push({"sign":"","hex":h16,"name":"字"+idx,"idx":idx,"bool":"","int32":int32,"uint32":uint32,"int16":int16,"uint16":uint16,"float32":float32,"double64":double64,"int64":int64,"uint64":uint64});
					idx++;

				}
			}
			//console.log(datatype,cmddata,len);
			reloadTable();
		}

		function reloadTable(){
			table2.reload("dataTable",{"elem":"#dataTable",data:cmddata});
		}

		$.ajax({
                async: false,
                type: "GET",
                url: '/xapi/sysconfig',
                success: function (data) {
					var list = data["ports"];
                    var c=0;
                    var s = '<option value="">选择通讯端口</option>';
                    $.each(list, function (i, xx) {
                            if (xx.name.startsWith("COM")) {
								var opt= xx["opts"];
								if (c==0 ){ selected ='selected="selected"'}else{selected =""};c++;
								s = s + '<option label="'+xx["type"]+'" '+selected+' value="' + xx.name + '">' + xx.name +"("+xx["type"] +"@"+opt["baudRate"] + " " + opt["dataBits"]   + parseParityMode(opt["parityMode"]) + opt["stopBits"]  +")"+ '</option>';
							}
                     });
                     $("#port_name").html(s);
                     form.render('select');
                }
            });
		
		var funcCodelist = [];
		$.ajax({
                async: false,
                type: "GET",
                url: '/api/protocol.json?_='+new Date(),
                success: function (data) {
					var list = data["modbus-rtu"]["poll"];
					funcCodelist = list;
                    var c = 0;
                    var s = '<option value="">选择功能码</option>';
                    $.each(list, function (i, xx) {
						var selected ="" ;
						if (c==0 ){ selected =''}else{selected =""};c++;//selected="selected"
						s = s + '<option '+selected+' value="' + xx.func + '">' + xx.func +" 0X"+ num2Hex(parseInt(xx.func) ) + xx.name +"("+xx["desc"]   +")"+ '</option>';
                     });
                     $("#funcCode").html(s);
                     form.render('select');
					 updaterestraint();
					 }
            });

 

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;
		  //自定义验证规则
		form.verify({
			slaveid: function(value){ 
				if (value.trim()==""){
					return "请输入从机地址(范围0-255十进制数字)";
				}else{
					return verifyslaveid(value);
				}

			},
			address:function(value){ 
				if (value.trim()=="")return '请输入寄存器地址'; 
			},
			quantity:function(value){ 
				if (value.trim()==""){
					return "请输入操作寄存器数量";
				}else{
					return verifyregcount(value);
				}
			},
			funcCode:function(value){ 
				if (value.trim()=="")return '请选择功能码'; 
			},
			cmd_name: function(value){ 
				if (value.trim()=="")return '请输入指令名称'; 
			},
			port_name:function(value){ 
				if (value.trim()==""){
					return "请选择通讯端口";
				}else{
					return verifyslaveid(value);
				}
			}
		});
        //监听提交
        form.on('submit(saveBtn)', function (data) {
			submitform(data.field,"PUT","command");
            return false;
        });

		form.on('submit(testBtn)', function (data) { 
			responsecmds =[];
			submitform(data.field,"POST","testcommand");
            return false;
        });

		function submitform(sdata,method,targeturl){
			//console.log($("#port_type").val());
			var spt=$("select[id=port_name]")["0"];//.selectedIndex;
			//$("#port_type").val( ($(spt.options[spt.selectedIndex]).attr("label")));
			sdata["port_type"]= ($(spt.options[spt.selectedIndex]).attr("label"));
			sdata["slaveid"]= parseInt(sdata["slaveid"]);
			sdata["funcCode"]= parseInt(sdata["funcCode"]);
			sdata["byteOrder"]=  $('input[name="selbyteorder"]:checked').val();
			if (addrMode=="Hex"){
				 sdata["address"] = parseInt("0x"+sdata["address"] );
			}else{
 				sdata["address"]= parseInt(sdata["address"]);
			}
 			sdata["quantity"]= parseInt(sdata["quantity"]);//if(!isEmpty(responsecmds)) 
			sdata["parser_rules"]= responsecmds;
			//console.log(isEmpty(responsecmds),sdata);
           /*var index = layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            }, function () { 
                // 关闭弹出层
                //layer.close(index);
                //layer.close(parentIndex);
            });*/
			//console.log(JSON.stringify(data.field));
			//cleanDatTable();
			$.ajax({
                async: false,
                type: method,//"POST",
                url: '/xapi/'+targeturl, //testcommand',
				data:JSON.stringify(sdata),
				headers : {'Content-Type' : 'application/json;charset=utf-8'}, 
                success: function (data) {
					//console.log(data);
					if (targeturl=="testcommand") {
						if (data["code"]==0) {
							//执行成功
							$("#pollresponse").val(insertstr(data["data"]," ",2));
							//displaydatTable(1,(data["data"].length/2*8),hex2binarystr(data["data"]));
							displaydatTable(data["data"],$("#data_type").val());
						}else{
							$("#pollresponse").val(data.desc + "," + data.data);
							displaydatTable([],$("#data_type").val());
						}
						
					}else if (targeturl=="command") {
						//保存模式
						//if (data["code"]==0) {

							var index = layer.msg("保存"+(data.code ==0 ? "成功.":"出错.")+data.desc, {
								icon: 1+data.code,
								time: 1000
								//title: '提示',
								//msg:"data.desc"
							}, function () { 
								// 关闭弹出层
								//$(window.parent.document).find("#refershbtn").children()[1].click();
								//parent.loadCmdData();
								if (data.code==0){
									$(window.parent.document).find("#refershbtn").trigger("click");
									layer.close(index);
									layer.close(parentIndex);
								}
							});
					}
                }
            });
		}

        $('#closeBtn').click(function () {
				clearInterval(myInterval);
				$(window.parent.document).find("#refershbtn").trigger("click");
                layer.close(parentIndex);
        });
		
		form.on('select(funcCode)', function (data) {
			updaterestraint();
        });
		function verifyslaveid(v){
			 var func = funcCodelist[$("select[name=funcCode]")["0"].selectedIndex-1];
			 if (func==null ) return ""
			 var min_addr = parseInt(func["min_addr"]);
			 var max_addr = parseInt(func["max_addr"]);
			 if ( parseInt(v)<min_addr || parseInt(v)>max_addr ){
				return "从机地址必须在("+min_addr+"~"+max_addr+")之间.";
			 }
		}
		function verifyregcount(v){
			var func = funcCodelist[$("select[name=funcCode]")["0"].selectedIndex-1];
			if (func==null ) return ""
			var quantity_max = parseInt(func["quantity_max"]);
			var quantity_min = parseInt(func["quantity_min"]);
			if ( parseInt(v)<quantity_min || parseInt(v)>quantity_max ){
				return "寄存器数量必须在("+quantity_min+"~"+quantity_max+")之间.";
			}			
		}
		function updaterestraint(){
				  //console.log($("select[name=funcCode]")["0"].selectedIndex );
				  var func = funcCodelist[$("select[name=funcCode]")["0"].selectedIndex-1];
				  if (func==null)return ;
				  var quantity_min = func["quantity_min"];
				  var quantity_max = func["quantity_max"];
				  var def_addr = func["def_addr"];
				  var data_type = func["data_type"];

				  //console.log($("select[name=funcCode]"));
                  //$("#slaveid").val(def_addr);
                  $("#data_type").val(data_type);	
				  
				  if (quantity_max==1 ){
					$("#quantity").val(quantity_max);
					$("#quantity").attr("readonly",true);
				  }else{
					$("#quantity").attr("readonly",false);					
				  }
             makeReq(this);
		}
		var lastaddrMode="";
		form.on('radio(ChoiceRadio)', function(data){
 		    addrMode = data.value;
			if (lastaddrMode == addrMode )return ;
			lastaddrMode = addrMode;
			if (addrMode=="Dec"){
				var cv=$("#address").val();
				cv = cv.replaceAll("0x","");
				$("#address").val(hex2Number(cv));
				$("#address").max = 65535;
				$("#address").min = 0;
				//$("#address").addEventListener("input",");
				/*$("#address").on('input porpertychange',function(e){
					this.value=this.value.replace(/[^0-9]/g,'');
				})*/
			}else{
				/*$("#address").on('input porpertychange',function(e){
					this.value=this.value.replace(/[^0-9a-fA-F]/g, '');
				})*/
				$("#address").val(""+num2Hexs($("#address").val()));
				$("#address").max = 65535;
			}			
		});  
		
		form.on('radio(selbyteorder)', function(data){
			
 		    //$("#testBtn").trigger("click");
			var v=$('input[name="selbyteorder"]:checked').val();
			addCookie("selbyteorder",v,100000) ;
			$("#testBtn").trigger("click");

		});
		var myInterval;
		var testcount=0;
		$('#looptestBtn').click(function () {

			 if ($('#looptestBtn').text().startsWith("停止测试")){
				testcount=0;
				$('#looptestBtn').text("循环测试");
				$('#looptestBtn').removeClass("layui-btn-danger");
				clearInterval(myInterval);
			 }else{
				$('#looptestBtn').text("停止测试");
				myInterval  = window.setInterval(looptest, 1000);
				$('#looptestBtn').addClass("layui-btn-danger");
			 }
        });

		function looptest(){
			testcount++;
			$('#testBtn').trigger('click');
			$('#looptestBtn').text("停止测试("+testcount+")");
		}

		 
    });

</script>